package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


@RestController("adminDishController")
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品相关接口")
public class DishController {


    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     *
     * @param dishDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增菜品")
    public Result addDish(@RequestBody DishDTO dishDTO) {
        log.info("新增菜品信息:{}", dishDTO);
        dishService.addWithFlavors(dishDTO);
        return Result.success();
    }

    /**
     * 分页查询菜品信息
     *
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        log.info("分页查询信息:{}", dishPageQueryDTO);
        PageResult dishVO = dishService.page(dishPageQueryDTO);
        return Result.success(dishVO);
    }

    /**
     * 删除菜品及其口味
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除菜品及其口味")
    public Result deleteDish(@RequestParam List<Long> ids) {
        log.info("删除菜品的id：{}", ids);
        dishService.del(ids);
        return Result.success();
    }

    /**
     * 根据id查询菜品信息
     *
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品信息")
    public Result<DishVO> getById(@PathVariable Long id) {
        log.info("需要查询的id：{}", id);
        DishVO dishVO = dishService.getById(id);
        return Result.success(dishVO);
    }

    /**
     * 修改菜品信息
     *
     * @param dishDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改菜单信息")
    public Result update(@RequestBody DishDTO dishDTO) {
        log.info("需要修改的菜单信息:{}", dishDTO);
        dishService.updateWithFlavors(dishDTO);
        return Result.success();
    }

    /**
     * 起售、停售菜品
     *
     * @return
     */
    @ApiOperation("起售、停售菜品")
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status, Long id) {
        log.info("需要修改的菜品id：{}，菜品的状态为：{}", id, status);
        dishService.updateStatus(status,id);
        return Result.success();
    }

    /**
     * 更具分类id查询菜品
     * @param categoryId
     * @return
     */
    @ApiOperation("根据分类id查询菜品")
    @GetMapping("/list")
    public Result<List<DishVO>> list(Long categoryId){
        log.info("分类id为:{}", categoryId);
        List<DishVO> dishList  = dishService.list(categoryId);
        return Result.success(dishList);
    }


}
